#!/usr/bin/env python

import re
import sys



def main():
    kegg_name = None
    ncbi_name = None
    link = None

    html = sys.stdin.read()
    for grp in html.split('\n\n'):
        grp = grp.replace('\n', ' ')
        if 'Name</nobr></th>' in grp:
            m = re.match(r""".+<div style="width:555px;overflow-x:auto;overflow-y:hidden">([a-z]+),?.+""", grp)
            kegg_name = m.groups()[0]
        elif 'Sequence</nobr></th>' in grp:
            m = re.match(r""".+([A-Z]{2}_[0-9]+)<.+""", grp)
            if m:
                ncbi_name = m.groups()[0]
            else:
                print >> sys.stderr, 'Cannot parse data for "%s"' % kegg_name
        elif 'Reference</nobr></th>' in grp:
            m = re.match(r""".+<a href="(http://.+)">[0-9]+</a>.+""", grp)
            if m:
                link = m.groups()[0]

    print '%s\t%s\t%s' % (kegg_name, ncbi_name, link)

main()

